define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'banner/index' + location.search,
                    add_url: 'banner/add',
                    edit_url: 'banner/edit',
                    del_url: 'banner/del',
                    multi_url: 'banner/multi',
                    import_url: 'banner/import',
                    table: 'banner',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                search: false,
                showSearch: false,
                showToggle: false,
                showColumns: false,
                showExport: false,
                searchFormVisible:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'path', title: __('Path'), operate: false,formatter: Table.api.formatter.image},
                        {field: 'title', title: __('Title'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'status', title: '状态', searchList: {"1":__('显示'),"2":__('隐藏')}, formatter: Table.api.formatter.status},

                        {field: 'displayorder', title: __('Displayorder'),operate: false},



                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.setTypeHtml($('#c-type').val());
            Controller.api.bindevent();
        },
        api: {
            setTypeHtml(val){
                $('.need-html,.article-html').hide();
                if (val == 1) {
                    $('.need-html').show();
                }
                if (val == 3) {
                    $('.article-html').show();
                }
            },
            bindevent: function () {
                $('#c-type').change(function (){
                    var val = $(this).val();
                    Controller.api.setTypeHtml(val);
                })
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
